package com.wangzh.game;

import java.util.Random;

public class Role {

    private String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    //定义一个方法，攻击别人
    public void attack(Role role) {
        //计算造成的伤害
        Random r = new Random();
        int hut = r.nextInt(20) + 1;
        int remainBoold = role.getBlood() - hut;
        remainBoold = remainBoold < 0 ? 0 : remainBoold;

        role.setBlood(remainBoold);
        System.out.println(this.name + "去起来拳头，打了" + role.getName() + "一下，" +
                "造成了"+hut+"伤害，"+role.getName()+"还剩下了"+remainBoold+"点血");
    }
}
